#include<iostream>
using namespace std;
const int N = 1e4 + 10;
int n;
int a[N];
int f[N];
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	int ma = 0;
	for (int i = 1; i <= n; i++) {
		f[i] = max(f[i - 1] + a[i], a[i]);
		/*if (f[i - 1] + a[i] >= 0)f[i] = f[i - 1] + a[i];
		else f[i] = a[i];*/
		cout << "i==" << i << endl;
		cout << "f[i]==" << f[i] << endl;
		ma = max(f[i], ma);
	}
	cout << ma << endl;
	return 0;
}